package ccmis.finance.account.dao;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.QueryHint;
import ccmis.finance.account.entity.SubjectList;
import jfox.platform.common.PaginationList;
import jfox.platform.infrastructure.EntityObject;
import jfox.platform.infrastructure.SuperDAO;
@Stateless
@Local
@NamedNativeQueries(
		{
	    @NamedNativeQuery(
	           		 //根据取得所有科目
	                   name = SubjectListDAOBean.GET_ALL_SUBJECTLIST,
	                   query =" SELECT * FROM T_FINANCEAL_SUBJECT_LIST "+
	                          " WHERE  VSTATUS=" + EntityObject.VSTATUS_NORMAL,
	                   resultClass =SubjectList.class,
	                   hints = {
	                   @QueryHint(name = "cache.partition", value = "function")
	                           }
	          ),
	    @NamedNativeQuery(
		           		 //根据取得所有科目总记录数
		                   name = SubjectListDAOBean.GET_ALL_SUBJECTLIST_COUNT,
		                   query =" SELECT COUNT(*) FROM T_FINANCEAL_SUBJECT_LIST "+
		                          " WHERE  VSTATUS=" + EntityObject.VSTATUS_NORMAL,
		                   resultClass =int.class
		                  
		          ),
        @NamedNativeQuery(
           		 //根据id取得科目
                   name = SubjectListDAOBean.GET_SUBJECTLIST_BY_ID,
                   query =" SELECT * FROM T_FINANCEAL_SUBJECT_LIST WHERE ID=$ID "+
                          " WHERE  VSTATUS=" + EntityObject.VSTATUS_NORMAL,
                   resultClass =SubjectList.class,
                   hints = {
                   @QueryHint(name = "cache.partition", value = "function")
                           }
          ),
        @NamedNativeQuery(
        		 //根据subjectId取得科目
                name = SubjectListDAOBean.GET_SUBJECTLIST_BY_SUBJECTID,
                query =" SELECT * FROM T_FINANCEAL_SUBJECT_LIST "+
                       "  WHERE SUBJECT_ID=$SUBJECT_ID "+
                       " AND VSTATUS=" + EntityObject.VSTATUS_NORMAL,
                      
                resultClass =SubjectList.class,
                hints = {
                @QueryHint(name = "cache.partition", value = "function")
                        }
        )
        }
  )
public class SubjectListDAOBean extends SuperDAO implements SubjectListDAO{
	public final static String GET_ALL_SUBJECTLIST ="SubjectListDAOBean.getAllSubjectList";
	public final static String GET_ALL_SUBJECTLIST_COUNT ="SubjectListDAOBean.getAllSubjectListCount";
	public final static String GET_SUBJECTLIST_BY_ID = "SubjectListDAOBean.getSubjectListById";
	public final static String GET_SUBJECTLIST_BY_SUBJECTID= "SubjectListDAOBean.getSubjectListBySubjectID";
    public PaginationList<SubjectList> getAllSubjectList(int start, int limit){
    	Map<String,Object> paramMap = new HashMap<String, Object>(2);
    	paramMap.put("LIMIT", limit);
        paramMap.put("CURRENTROWS", start + limit);
    	int totalCount =(Integer)processNamedNativeQuerySingle(SubjectListDAOBean.GET_ALL_SUBJECTLIST_COUNT,paramMap);
    	List<SubjectList> sub= (List<SubjectList>)processNamedNativeQuery(SubjectListDAOBean.GET_ALL_SUBJECTLIST,paramMap,start,limit);
    	return new PaginationList(sub, totalCount);
    }
	public SubjectList getSubjectListById(long id){
    	return (SubjectList)getEntityObjectByColumn(SubjectListDAOBean.GET_SUBJECTLIST_BY_ID,"ID",id);
    }
    public SubjectList getSubjectListBySubjectId(String subjectId){
    	return (SubjectList)getEntityObjectByColumn(SubjectListDAOBean.GET_SUBJECTLIST_BY_SUBJECTID,"SUBJECT_ID",subjectId);
    }
}
